package mvc.handlerexception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Administrator
 */

@ControllerAdvice
public class GlobalExceptionHandler {

    //指定出现什么异常执行这个方法
    @ExceptionHandler(Exception.class)
    @ResponseBody //为了返回数据
    public String error(Exception e) {
        e.printStackTrace();
        return  e.getMessage();
    }

    //特定异常
    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody //为了返回数据
    public String error(ArithmeticException e) {
        e.printStackTrace();
        return  e.getMessage();
    }


    //特定异常
    @ExceptionHandler(MyException.class)
    @ResponseBody //为了返回数据
    public String error(MyException e) {
        e.printStackTrace();
        return  e.getMessage();
    }
}
